﻿#region 版权说明
/**********************************************************************
      * 功能说明:
      * 
      * CLR 版本:       4.0.30319.18033
      * 类 名 称:       CommonHelper
      * 命名空间:       Devil_System.Helper
      * 创建时间:       2013-05-09 09:00:59
      * 作    者:       Devil月哥
      * 版    权:       CommonHelper说明：本代码版权归Devil月哥所有 All Rights Reserved (C) 2013 - 2013
      * 网    站:       http://www.xd5u.com
      * 邮    箱:       webmaster@xd5u.com
      * 唯一标识：      673875b5-5d31-4d5a-8fca-85acedae3bc2  

      * 修改时间:
      * 修 改 人:
      * 
      ***********************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Devil_System.Helper
{
    public class CommonHelper
    {

        #region StartProcess启动带参数程序
        /// <summary>
        /// 启动带参数程序
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static bool StartProcess(string filename, string[] args)
        {
            bool returns = false;

            try
            {
                string s = "";
                foreach (string arg in args)
                {
                    s = s + arg + " ";
                }
                s = s.Trim();
                System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(filename, s);
                myprocess.StartInfo = startInfo;
                myprocess.StartInfo.UseShellExecute = false;
                myprocess.Start();
                returns = true;
            }
            catch (Exception ex)
            {
                returns = false;
                throw ex;
            }
            return returns;
        }
        #endregion

        #region GetFileVersion获取文件版本号
        /// <summary>
        /// 获取文件版本号
        /// </summary>
        /// <param name="Fileulr"></param>
        /// <returns></returns>
        public static string GetFileVersion(string Fileulr)
        {
            string returns;
            try
            {
                System.Diagnostics.FileVersionInfo FileVersion1 =
                    System.Diagnostics.FileVersionInfo.GetVersionInfo(Fileulr);

                returns = FileVersion1.FileVersion;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returns;
        }
        #endregion

        #region GetRunDirectory取程序运行目录
        /// <summary>
        /// 取程序运行目录
        /// </summary>
        /// <returns></returns>
        public static string GetRunDirectory()
        {
            string returns;
            try
            {
                string rundirectory = System.Environment.CurrentDirectory;
                returns = rundirectory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returns;
        }
        #endregion

        #region GetRunDirectoryApp取程序运行基目录
        /// <summary>
        /// 取程序运行基目录+/
        /// </summary>
        /// <returns></returns>
        public static string GetRunDirectoryApp()
        {
            string returns;
            try
            {
                returns = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returns;
        }
        #endregion

        #region GetRunFlie取当前程序路径
        /// <summary>
        /// 取当前程序路径
        /// </summary>
        /// <returns></returns>
        public static string GetRunFlie()
        {
            string returns;
            try
            {
                returns = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return returns;
        }
        #endregion
    }
}
